package com.msmall.community.admin.action;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantDB;
import com.msmall.base.util.ConstantUrl;
import com.msmall.community.common.model.Config;
import com.msmall.community.common.service.ConfigManager;

public class ConfigAction extends HTMLBaseAction{

	private static final long serialVersionUID = 3057535151406168607L;

	private Long configId;
	
	private Config config;
	
	private ConfigManager configManager;

	public String execute(){
		page.setClazz(Config.class);
		page.setOrderBy("configId");
		page.setOrder("asc");
		page.setPageSize(10);
		configManager.getPagination(page);
		page.setUrl(ConstantUrl.ADMIN_CONFIG_INDEX);
		return SUCCESS;
	}
	
	public String create(){
		config = null;
		return SUCCESS;
	}
	
	public String update(){
		config = (Config) configManager.get(Config.class, configId);
		return SUCCESS;
	}
	public String save(){
		if(config.getEnabled() == null){
			config.setEnabled(ConstantDB.UNAVALIABLE);
		}
		configManager.saveConfig(config);
		return execute();
	}

	public Long getConfigId() {
		return configId;
	}

	public void setConfigId(Long configId) {
		this.configId = configId;
	}

	public Config getConfig() {
		return config;
	}

	public void setConfig(Config config) {
		this.config = config;
	}

	public void setConfigManager(ConfigManager configManager) {
		this.configManager = configManager;
	}
}
